package com.zyd.shiro.controller.admin;
import java.util.List;
import java.util.Map;

import com.zyd.shiro.business.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zyd.shiro.persistence.beans.User;
import com.zyd.shiro.business.service.MallUserService;

import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
/**
 * 控制器层
 * @author RookieWZW
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

	@Autowired
	private MallUserService userService;
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public ResponseVO findAll(){
		List<UserVO> userVOList = userService.findAll();
		 return ResultUtil.success("查询成功",ResultUtil.tablePage((long) userVOList.size(),userVOList));
		
	}
	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResponseVO findOne(@PathVariable Integer id){
		return ResultUtil.success("查询成功", userService.findOne(id));	
		
	}

	/**
	 * 条件查询
	 * @param searchMap 查询条件封装
	 * @return 分页结果
	 */
	@RequestMapping(value="/findSearch",method=RequestMethod.POST)
	public ResponseVO findSearch(@RequestBody Map searchMap ){
		List<UserVO> userVOList = userService.findSearch(searchMap);
		return ResultUtil.success("查询成功",  ResultUtil.tablePage((long) userVOList.size(),userVOList) );

	}



	/**
	 * 删除
	 * @param id
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public ResponseVO delete(@PathVariable Integer id ){
		userService.delete(id);
		return ResultUtil.success("删除成功");
	}

	//--------------------------------------------------------------------------------------------------------------



}
